<!--
  轮播图卡片组件
  用于展示多个信息卡片的轮播效果，支持自动播放和背景图片
-->
<template>
  <div class="carousel-container" :style="containerStyle">
    <el-carousel
      :interval="autoPlay ? interval : 0"
      :height="carouselHeight"
      indicator-position="outside"
      arrow="never"
    >
      <el-carousel-item v-for="(card, index) in cards" :key="index">
        <div
          class="carousel-slide"
          :style="getSlideStyle(card)"
        >
          <div class="carousel-content">
            <InfoCard
              :title="card.title"
              :description="card.description"
              :meta="card.meta"
              :tags="card.tags"
              :icon="card.icon"
              :highlight="true"
            >
            </InfoCard>
          </div>
        </div>
      </el-carousel-item>
    </el-carousel>
  </div>
</template>

<script setup>
import { computed } from 'vue'
import { ElCarousel, ElCarouselItem } from 'element-plus'
import InfoCard from './InfoCard.vue'

const props = defineProps({
  cards: {
    type: Array,
    required: true,
    default: () => [],
  },
  autoPlay: {
    type: Boolean,
    default: true,
  },
  interval: {
    type: Number,
    default: 5000,
  },
  height: {
    type: String,
    default: '450px',
  },
  fullWidth: {
    type: Boolean,
    default: true,
  },
})

const carouselHeight = computed(() => {
  if (props.height === 'auto') {
    return '450px'
  }
  return props.height
})

const containerStyle = computed(() => {
  if (props.fullWidth) {
    return {
      width: '100%',
      maxWidth: '100%',
    }
  }
  return {}
})

function getSlideStyle(card) {
  const style = {}
  if (card.backgroundImage) {
    style.backgroundImage = `url(${card.backgroundImage})`
    style.backgroundSize = 'cover'
    style.backgroundPosition = 'center'
    style.backgroundRepeat = 'no-repeat'
    style.width = '100%'
    style.maxWidth = '100%'
  }
  return style
}
</script>

<style scoped>
.carousel-container {
  width: 100%;
  max-width: 100%;
  position: relative;
  overflow: hidden;
  box-sizing: border-box;
}

.carousel-slide {
  position: relative;
  width: 100%;
  max-width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 60px 20px;
  min-height: 450px;
  box-sizing: border-box;
  overflow: hidden;
}

.carousel-slide::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.3);
  z-index: 1;
}

.carousel-content {
  position: relative;
  z-index: 2;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
}

/* 轮播图内部卡片透明效果 */
.carousel-content :deep(.info-card) {
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-color: rgba(255, 255, 255, 0.3);
}

.carousel-content :deep(.info-card:hover) {
  background: rgba(255, 255, 255, 0.95);
  border-color: rgba(255, 255, 255, 0.5);
}

:deep(.el-carousel__container) {
  height: 100%;
}

:deep(.el-carousel__item) {
  height: 100%;
}

:deep(.el-carousel__indicators) {
  margin-top: 20px;
  z-index: 3;
}

:deep(.el-carousel__arrow) {
  z-index: 3;
}

.action-link {
  font-size: 14px;
  color: #409eff;
  text-decoration: none;
  font-weight: 500;
}

.action-link:hover {
  text-decoration: underline;
}

@media (max-width: 768px) {
  .carousel-slide {
    padding: 40px 16px;
    min-height: 350px;
  }
}
</style>

